/**
 * Created by udi on 2016/11/28.
 */


require(["jv", "vue"], function () {
  var Vue = require("vue");

  Vue.config.ignoredElements = ["kv", "k", "v"];

  if (!location.map.token) {
    jv.setToken();
  }

  var skip = 0, take = 5;

  var vm = jv.vm = new Vue({
    el: '#app',
    data: {items: [], loading: true},
    computed: {},
    methods: {
      getTime: function (dt) {
        var now = new Date();
        dt = new Date(dt);
        if( now.getFullYear() == dt.getFullYear()){
          return dt.toString("MM-dd HH:mm");
        }
        return dt.toString("yyyy-MM-dd HH:mm");
      }
    }
  });


  var bindVue = function (data) {
    skip += data.length;
    data.splice(0, 0, jv.vm.$data.items.length);
    data.splice(1, 0, 0);
    jv.vm.$data.items.splice.apply(jv.vm.$data.items, data);
    if (jv.vm.$data.items.length < take) {
      jv.vm.$data.loading = false;
    }
  }

  jv.scroll2Bottom(function () {
    jv.post("/message/list", {skip: skip, take: take}, bindVue);
  }, true);
});
